﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Entity;
using PearTunes.Model;

namespace PearTunes.DAL
{
    /// <summary>
    /// Initializes the sample database if the model changes
    /// </summary>
    public class SampleDataInitializer :  DropCreateDatabaseIfModelChanges<PearTunesEntities>
    {
        /// <summary>
        /// Seeds the database with sample data
        /// </summary>
        /// <param name="context">The context to wich the data is seeded to</param>
        protected override void Seed(PearTunesEntities context)
        {


            var tracks = new List<Track>
            {
                new Track { Artist="Beatles", Genre="Rock", Price=21, Title="Yellow Submarine", TrackNumber=2, Year=1964},//,  Albums= new List<Album>()},
                new Track { Artist="Beatles", Genre="Rock", Price=41, Title="Hey Jude", TrackNumber=4, Year=1966},//,  Albums= new List<Album>()},
                new Track { Artist="Beatles", Genre="Rock", Price=26, Title="Here Comes The Sun", TrackNumber=7, Year=1963,}//  Albums= new List<Album>()}
            };
            var albums = new List<Album>
            {
                new Album { Title="Beatles1", Price=100, Tracks= new List<Track>()},
                new Album { Title="Beatles2", Price=130, Tracks= new List<Track>()}
            };

            albums[0].Tracks.Add(tracks[0]);
            albums[0].Tracks.Add(tracks[1]);
            albums[1].Tracks.Add(tracks[2]);

            albums.ForEach(p => context.Albums.Add(p));
            context.SaveChanges();
        }

    }
}
